package com.kevin.chat.framework.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kevin.chat.entity.UserEntity;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class JSONUtil {
    private static ObjectMapper mapper=new ObjectMapper();

    /**
     * map 转json字符串
     * @param obj
     * @return
     * @throws JsonProcessingException
     */
    public static String writeValueAsString(Object obj) throws JsonProcessingException {
        return mapper.writeValueAsString(obj);
    }

    /**
     *
     * @param json
     * @param clazz
     * @return
     * @throws IOException
     */
    public static Map readValue(String json,Class clazz) throws IOException {
        return (Map) mapper.readValue(json, clazz);
    }
}
